#!/bin/bash

echo "========================================"
echo "验证项目配置"
echo "========================================"
echo ""

# 检查 Node.js
echo "[1/4] 检查 Node.js..."
if ! command -v node &> /dev/null; then
    echo "[X] 未找到 Node.js"
    exit 1
else
    node --version
    echo "[OK] Node.js 已安装"
fi
echo ""

# 检查 Java
echo "[2/4] 检查 Java..."
if ! command -v java &> /dev/null; then
    echo "[X] 未找到 Java"
    exit 1
else
    java -version
    echo "[OK] Java 已安装"
fi
echo ""

# 检查 Maven
echo "[3/4] 检查 Maven..."
if ! command -v mvn &> /dev/null; then
    echo "[X] 未找到 Maven"
    exit 1
else
    mvn --version
    echo "[OK] Maven 已安装"
fi
echo ""

# 测试编译
echo "[4/4] 测试编译..."
echo ""

echo "[4.1] 测试智能合约编译..."
cd blockchain
npm install --silent 2>/dev/null
npm run compile
if [ $? -ne 0 ]; then
    echo "[X] 智能合约编译失败"
    cd ..
    exit 1
fi
echo "[OK] 智能合约编译成功"
cd ..
echo ""

echo "[4.2] 测试后端编译..."
cd backend
mvn clean compile -DskipTests -q
if [ $? -ne 0 ]; then
    echo "[X] 后端编译失败"
    cd ..
    exit 1
fi
echo "[OK] 后端编译成功"
cd ..
echo ""

echo "========================================"
echo "所有检查通过！"
echo "========================================"
echo ""
echo "项目配置正确，可以开始使用。"
echo ""
echo "运行以下命令启动系统："
echo "  Windows: start.bat"
echo "  Linux/Mac: ./start.sh"
echo ""




